<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>

function sumArray(arr) {
    return arr.reduce((acc, val) => acc + val, 0);
}

// 示例使用
const array = [1, 2, 3, 4, 5];
console.log(sumArray(array)); // 输出: 15

// 也可以使用箭头函数
 const sumArray2 = (arr) => arr.reduce((acc, val) => acc + val, 0);
 console.log(sumArray2(array)); // 输出: 15

  



</script>